#include <list>
#include <WinSock2.h>
#include <thread>
#include "SDL_ttf.h"
#include "DataDefine.h"
#include "Button.h"
#include "Player.h"
#include "Checker.h"
#include "Animation.h"

using namespace std;

char* windowPixels;

TTF_Font* mainTitleFont;
TTF_Font* buttonFont;
TTF_Font* costFont;
TTF_Font* descFont;
TTF_Font* titleFont;
TTF_Font* attributeFont;
TTF_Font* GUICostFont;
TTF_Font* ResultFont;

SDL_Color colorBlack = { 0, 0, 0 };
SDL_Color colorWhite = { 255, 255, 255 };

SDL_Window* window;

SDL_Renderer* renderer;

SDL_Texture* mainmenuButtonTexture;
SDL_Texture* mainmenuButtonPressedTexture;
SDL_Texture* turnChangeButtonTexture;
SDL_Texture* turnChangeButtonPressedTexture;
SDL_Texture* backButtonTexture;
SDL_Texture* backButtonPressedTexture;
SDL_Texture* PlayerTurnChangeTexture;
SDL_Texture* EnemyTurnChangeTexture;
SDL_Texture* mapTexture;
SDL_Texture* hitTexture;
SDL_Texture* cardTexture;
SDL_Texture* cardBackTexture;
SDL_Texture* checkerSideSelfTexture;
SDL_Texture* checkerSideEnemyTexture;
SDL_Texture* netBGTexture;
SDL_Texture* netPointerTexture;
SDL_Texture* gameoverBGTexture;
SDL_Texture* cardTitleTexture;

SDL_Surface* cardSurface;

int globalState = MAINMENU;
int targetState;
int selectState;

bool isQuit = false;

bool isSceneChanging = false;
bool isTurnChanging = false;
bool isGameOverChanging = false;
bool isAnimation = false;
bool isSelecting = false;
bool mapSelectBuffer = false;
bool directAttack = false;
bool isSelectingDirectAttack = false;
int globalCounter = 0;

list<Button*> mainmenuButtonList;
list<Button*> gameplayingButtonList;
list<Button*> gameoverButtonList;
list<Button*> netprocessButtonList;
list<Button*> deckeditButtonList;
list<Button*> aboutButtonList;

list<Button*>* currentButtonList;

list<Animation*> animationList;

int mouseX;
int mouseY;
int selectX;
int selectY;

list<Card*> usingDeck;
list<Card*> enemyDeck;

Card* cardShown;
int attackShown;
int healthShown;
int moveShown;
bool isShowingChecker = false;

list<int> destroyX;
list<int> destroyY;

Player* player = NULL;
Player* enemyPlayer = NULL;

Checker* board[7][9];
bool selectBoard[7][9];

bool isPlayerTurn = true;
bool isPlayerInitDone = false;

list<Handcard*>::iterator selectedCard;
list<Handcard*>::iterator enemySelectedCard;
int selectedCheckerX;
int selectedCheckerY;

bool isSinglePlayer;

list<string> ipAddressToLink;
string hostIp;
int ipPointed = 0;
wstring ipInfo;
bool ipSelectBuffer = false;
bool hasTcpLinked = false;
SOCKET* tcpSocket;

list<Card*> editingDeck;

Card* unitSelect[2][4];
Card* actionSelect[2][4];

int selectCardType = 1;
Card* selectedShownCard;

Card* (*cardptr)[2][4];

bool cardSelectBuffer = false;
bool deckSelectBuffer = false;

list<wstring> aboutText;
